using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace ShootThemUp.Sources.GameElements.Weapons
{
    /// <summary>
    /// This class represents a weapon, with a type and a reload time.
    /// </summary>
    public class Weapon
    {
        #region Fields

        /// <summary>
        /// Minimal Time between 2 shot of this weapon, in ms.
        /// </summary>
        private float reloadTime;
        /// <summary>
        /// The total time since the last shot, in ms.
        /// </summary>
        private float currentShotTime;
        /// <summary>
        /// The type of this weapon.
        /// </summary>
        private WeaponType weaponType;
        /// <summary>
        /// The number of projectiles at every shot.
        /// </summary>
        private int numberOfShot;
        /// <summary>
        /// The position of the shot texture in the sprite sheet, it is usefull to change the texture of a shot without change is deplacement. Null to use the default texture.
        /// </summary>
        private Rectangle? shotTexture = null;

        #endregion

        #region Properties

        /// <summary>
        /// Gets or sets the reload time, ie the time between two shot.
        /// </summary>
        /// <value>
        /// The reload time.
        /// </value>
        public float ReloadTime
        {
            get { return reloadTime; }
            set { reloadTime = value; }
        }

        /// <summary>
        /// Gets or sets the current shot time, ie the total time since the last shot.
        /// </summary>
        /// <value>
        /// The current shot time.
        /// </value>
        public float CurrentShotTime
        {
            get { return currentShotTime; }
            set { currentShotTime = value; }
        }

        /// <summary>
        /// Gets or sets the type of the weapon.
        /// </summary>
        /// <value>
        /// The type of the weapon.
        /// </value>
        public WeaponType WeaponType
        {
            get { return weaponType; }
            set { weaponType = value; }
        }

        /// <summary>
        /// Gets or sets the number of shot.
        /// </summary>
        /// <value>
        /// The number of shot.
        /// </value>
        public int NumberOfShot
        {
            get { return numberOfShot; }
            set { numberOfShot = value; }
        }

        /// <summary>
        /// Gets or sets the shot texture, ie the position of the shot texture in the sprite sheet, it is usefull to change the texture of a shot without change is deplacement. Null to use the default texture.
        /// </summary>
        /// <value>
        /// The shot texture.
        /// </value>
        public Rectangle? ShotTexture
        {
            get { return shotTexture; }
            set { shotTexture = value; }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="Weapon"/> class.
        /// </summary>
        /// <param name="reloadTime">The reload time.</param>
        public Weapon(WeaponType type, float reloadTime, int numberOfShot)
        {   
            this.reloadTime = reloadTime;
            this.currentShotTime = reloadTime;
            this.numberOfShot = numberOfShot;
            this.weaponType = type;
        }


        /// <summary>
        /// Initializes a new instance of the <see cref="Weapon"/> class.
        /// </summary>
        /// <param name="type">The type.</param>
        /// <param name="reloadTime">The reload time.</param>
        /// <param name="currentShotTime">The current shot time.</param>
        /// <param name="numberOfShot">The number of shot.</param>
        /// <param name="shotTexture">The shot texture.</param>
        public Weapon(WeaponType type, float reloadTime, float currentShotTime, int numberOfShot, Rectangle? shotTexture)
        {
            this.reloadTime = reloadTime;
            this.currentShotTime = currentShotTime;
            this.numberOfShot = numberOfShot;
            this.weaponType = type;
            this.shotTexture = shotTexture;
        }

        #endregion

        #region Methods

        /// <summary>
        /// Reloads the weapon.
        /// </summary>
        public void Reload()
        {
            this.currentShotTime = this.reloadTime;
        }

        /// <summary>
        /// Updates this weapon with the specified game time.
        /// </summary>
        /// <param name="gameTime">The game time.</param>
        public void Update(GameTime gameTime)
        {
            this.currentShotTime -= (float)gameTime.ElapsedGameTime.TotalMilliseconds;
        }

        #endregion
    }
}
